package com.stylefeng.guns.biz.page.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.page.model.TPageList;
import com.stylefeng.guns.biz.page.service.ITPageListService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 多页面控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:35:09
 */
@Controller
@RequestMapping("/tPageList")
public class TPageListController extends BaseController {

    private String PREFIX = "/app/tPageList/";

    @Autowired
    private ITPageListService tPageListService;

    /**
     * 跳转到多页面首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tPageList.html";
    }

    /**
     * 跳转到添加多页面
     */
    @RequestMapping("/tPageList_add")
    public String tPageListAdd() {
        return PREFIX + "tPageList_add.html";
    }

    /**
     * 跳转到修改多页面
     */
    @RequestMapping("/tPageList_update/{tPageListId}")
    public String tPageListUpdate(@PathVariable Long tPageListId, Model model) {
        TPageList tPageList = tPageListService.selectById(tPageListId);
        model.addAttribute("item",tPageList);
        LogObjectHolder.me().set(tPageList);
        return PREFIX + "tPageList_edit.html";
    }

    /**
     * 获取多页面列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	EntityWrapper<TPageList> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
        return tPageListService.selectList(wrapper);
    }

    /**
     * 新增多页面
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TPageList tPageList) {
        tPageListService.insert(tPageList);
        return SUCCESS_TIP;
    }

    /**
     * 删除多页面
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long tPageListId) {
        tPageListService.deleteById(tPageListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改多页面
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TPageList tPageList) {
        tPageListService.updateById(tPageList);
        return SUCCESS_TIP;
    }

    /**
     * 多页面详情
     */
    @RequestMapping(value = "/detail/{tPageListId}")
    @ResponseBody
    public Object detail(@PathVariable("tPageListId") Long tPageListId) {
        return tPageListService.selectById(tPageListId);
    }
}
